package cn.fl.project.controller;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.*;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.capital.condition.CapPayInfoQueryCondition;
import cn.fl.capital.vo.CapPayMaterialVo;
import cn.fl.commons.result.ResponseData;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.preloan.IProprdLicenseService;
import cn.fl.preloan.condition.PrjPrdLicInfoQueryCondition;
import cn.fl.preloan.dto.DeleteProprdLicenseRequest;
import cn.fl.preloan.dto.PrjPrdLicInfoDTO;
import cn.fl.preloan.dto.ProprdLicensePageResponseDTO;
import cn.fl.preloan.enums.PreloanResultCodeEnum;
import cn.fl.project.constant.PrjBscInfoConstant;
import cn.fl.project.service.*;
import cn.fl.project.vo.*;
import cn.fl.system.constant.SysLogConstant;
import cn.fl.system.vo.SysUlFilesRecVO;
import cn.fl.upload.constant.UploadConstant;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import fl.flow.facade.flow.constant.FlowConstant;
import net.sf.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Description: 项目车辆上牌信息表 控制层
 */
@Controller
@RequestMapping("/project/prjprdlicinfo")
public class PrjPrdLicInfoController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(PrjPrdLicInfoController.class);

	
	/**
	 * PrjPrdLicInfo 服务层BEAN
	 */
	@Autowired
	private IPrjPrdLicInfoService prjPrdLicInfoService;

	/**
	 * prjPrdDtlService 服务层BEAN
	 */
	@Autowired
	private IPrjPrdDtlService prjPrdDtlService;
	/**
	 * prjPrdDtlService 服务层BEAN
	 */
	@Autowired
	private IPrjPrdPaySchMService prjPrdPaySchMService;
	
	/**
	 * PrjPrdLicInfo 服务层BEAN
	 */
	@Autowired
	private IPrjPrdVehInfoService IPrjPrdVehInfoService;
	
	/**
	 * PrjPrdLicInfo 服务层BEAN
	 */
	@Autowired
	private IPrjBscInfoService prjBscInfoService;
	/**
	 * IPrjPrdMtgService 服务层BEAN
	 */
	@Autowired
	private IPrjPrdMtgService prjPrdMtgService;
	@Autowired
	private ISysDictionaryApiService  sysDictionaryApiService;
	@Autowired
	private IProprdLicenseService iProprdLicenseService;




	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage4Sys.do", method = { RequestMethod.GET})
	public ModelAndView toListPage4Sys(HttpServletRequest request, HttpServletResponse response) {
		List<KeyValueVO> provAbbrCdList = this.sysDictionaryApiService.getKvList(DictionaryConstant.CODE_PROV_ABBR_CD,CurrentThreadContext.getCurrentSysCd() , CurrentThreadContext.getCurrentOrgCd());
		List<KeyValueVO> characterList = new ArrayList<KeyValueVO>();
		for (int i = 0; i < 26; i++) {
			KeyValueVO keyValueVO = new KeyValueVO();
			String value =String.valueOf( (char) (65 + i));
			keyValueVO.setKey(value);
			keyValueVO.setValue(value);
			characterList.add(keyValueVO);
		}
		ModelAndView view = new ModelAndView("project/prjprdlicinfo/prjPrdLicInfoListPage4Sys");
		view.addObject("characterList", characterList);
		view.addObject("provAbbrCdList", provAbbrCdList);
		BaseLogUtils.info(logger, "toListPage", "跳转到列表页面.", CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 到添加页面
	 */
	@RequestMapping(value = "/toAddPage4Sys.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toAddPage4Sys(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		String dtlId = request.getParameter("dtlId");//明细ID
		String detailFlag = request.getParameter("detailFlag");//
		String isFlow = request.getParameter("isFlow");//是否为流程中跳转页面
		String checkSp = request.getParameter("checkSp");//是否有验证上牌信息的权限


		ModelAndView view = new ModelAndView("project/prjprdlicinfo/prjPrdLicInfoAddPage4Sys");
		view.addObject("isFlow", isFlow);
		view.addObject("checkSp", checkSp);
		PrjPrdLicInfoVO licInfo = null;
		if(StringUtils.isNotBlank(id)){
			licInfo =	this.prjPrdLicInfoService.selectById(Long.valueOf(id));
		}
		String recNo = "";
		//查找抵押信息
		PrjPrdMtgVO mtgVo = this.prjPrdMtgService.selectById(Long.valueOf(dtlId));
		if(null!=mtgVo&&StringUtils.isNotBlank(mtgVo.getRecNo())){
			recNo = mtgVo.getRecNo();
		}
		PrjPrdDtlVO dtlVO =  this.prjPrdDtlService.selectById(Long.valueOf(dtlId));
		PrjBscInfoVO prjBscInfo  = this.prjBscInfoService.selectById(dtlVO.getPrjId());
		String BuOrgCd = prjBscInfo.getBuOrgCd();
		view.addObject("BuOrgCd", BuOrgCd);
		// 事业部
		if(null!=dtlVO&&null!=dtlVO.getActPrdId()){
			PrjPrdVehInfoVO vehVO = this.IPrjPrdVehInfoService.selectById(dtlVO.getActPrdId());
			view.addObject("vehVO", vehVO);
			//查找项目的客户经理组织机构信息
			/*PrjBscInfoVO prjBscInfo  = this.prjBscInfoService.selectById(dtlVO.getPrjId());*/
		}
		if(prjBscInfo.getCstMgrOrgCd().contains(PrjBscInfoConstant.CODE_ORG_CD_YZDG)){
			List<String> orgCds = new ArrayList<String>();
			orgCds.add(PrjBscInfoConstant.CODE_ORG_CD_YZDG);
			view.addObject("orgCds", orgCds);
		}
		view.addObject("licInfo", licInfo);
		view.addObject("id", id);
		view.addObject("dtlVO", dtlVO);
		view.addObject("dtlId", dtlId);
		view.addObject("detailFlag", detailFlag);
		view.addObject("recNo", recNo);
		BaseLogUtils.info(logger, "toModifyPage", "跳转到修改页面.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		return view;
	}


	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET})
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		List<KeyValueVO> provAbbrCdList = this.sysDictionaryApiService.getKvList(DictionaryConstant.CODE_PROV_ABBR_CD,CurrentThreadContext.getCurrentSysCd() , CurrentThreadContext.getCurrentOrgCd());
		List<KeyValueVO> characterList = new ArrayList<KeyValueVO>();
		for (int i = 0; i < 26; i++) {
			KeyValueVO keyValueVO = new KeyValueVO();
			String value =String.valueOf( (char) (65 + i));
			keyValueVO.setKey(value);
			keyValueVO.setValue(value);
			characterList.add(keyValueVO);
		}
		ModelAndView view = new ModelAndView("project/prjprdlicinfo/prjPrdLicInfoListPage");
		view.addObject("characterList", characterList);
		view.addObject("provAbbrCdList", provAbbrCdList);
		BaseLogUtils.info(logger, "toListPage", "跳转到列表页面.", CurrentThreadContext.getCurrentUserName());
		return view;
	}
	/**
	 * 到添加页面
	 */
	@RequestMapping(value = "/toAddPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toAddPage(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		String dtlId = request.getParameter("dtlId");//明细ID
		String detailFlag = request.getParameter("detailFlag");
		String isFlow = request.getParameter("isFlow");//是否为流程中跳转页面
		String checkSp = request.getParameter("checkSp");//是否有验证上牌信息的权限
		String checkSpPass = request.getParameter("checkSpPass");//是否有验证上牌信息的权限
		//换车需求，dtl表中无prjId
		String prjId = request.getParameter("prjId");

		ModelAndView view = new ModelAndView("project/prjprdlicinfo/prjPrdLicInfoAddPage");
		view.addObject("isFlow", isFlow);
		view.addObject("checkSp", checkSp);
		PrjPrdLicInfoVO licInfo = null;
		if(StringUtils.isNotBlank(id)){
			 licInfo =	this.prjPrdLicInfoService.selectById(Long.valueOf(id));
		}
		String recNo = "";
		 //查找抵押信息
		 PrjPrdMtgVO mtgVo = this.prjPrdMtgService.selectById(Long.valueOf(dtlId));
		 if(null!=mtgVo&&StringUtils.isNotBlank(mtgVo.getRecNo())){
			 recNo = mtgVo.getRecNo();
		 }
		PrjPrdDtlVO dtlVO =  this.prjPrdDtlService.selectById(Long.valueOf(dtlId));
		Long projectId = dtlVO.getPrjId();
		if (projectId == null && StringUtils.isNotEmpty(prjId)) {
			projectId = Long.valueOf(prjId);
		}
		PrjBscInfoVO prjBscInfo  = this.prjBscInfoService.selectById(projectId);
		String prjTypCd = prjBscInfo.getPrjTypCd();  // 项目类型（PRJ0002）
		boolean isFlowStarted = false; // 流程是否以提交   // 项目类型：车抵贷业务线下
		if(prjBscInfo.getPrjStsCd() !=null && !prjBscInfo.getPrjStsCd().equals(FlowConstant.FLOW_CHECK_STATE_NON)
				&& StringUtils.isNotBlank(prjTypCd) && prjTypCd.equals("CDDYWUL")) {
			isFlowStarted = true;
		}
		String BuOrgCd = prjBscInfo.getBuOrgCd();
		view.addObject("BuOrgCd", BuOrgCd);
		// 事业部
		if(null!=dtlVO&&null!=dtlVO.getActPrdId()){
			PrjPrdVehInfoVO vehVO = this.IPrjPrdVehInfoService.selectById(dtlVO.getActPrdId());
			view.addObject("vehVO", vehVO);
			//查找项目的客户经理组织机构信息
			/*PrjBscInfoVO prjBscInfo  = this.prjBscInfoService.selectById(dtlVO.getPrjId());*/
		}
		if(prjBscInfo.getCstMgrOrgCd().contains(PrjBscInfoConstant.CODE_ORG_CD_YZDG)){
			List<String> orgCds = new ArrayList<String>();
			orgCds.add(PrjBscInfoConstant.CODE_ORG_CD_YZDG);
			view.addObject("orgCds", orgCds);
		}
		view.addObject("licInfo", licInfo);
		view.addObject("id", id);
		view.addObject("dtlVO", dtlVO);
		view.addObject("dtlId", dtlId);
		view.addObject("detailFlag", detailFlag);
		view.addObject("recNo", recNo);
		view.addObject("isFlowStarted", isFlowStarted);
		view.addObject("prjTypCd", prjTypCd);
		view.addObject("checkSpPass", checkSpPass);
		view.addObject("prjId", prjId);
		BaseLogUtils.info(logger, "toModifyPage", "跳转到修改页面.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		return view;
	}

	
	/**
	 * 到修改页面
	 */
	@RequestMapping(value = "/toModifyPage.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		ModelAndView view = new ModelAndView("project/prjprdlicinfo/modify");
		view.addObject("id", id);
		BaseLogUtils.info(logger, "toModifyPage", "跳转到修改页面.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String cstNm = request.getParameter("cstNm");//客户名称
		String paySchNo = request.getParameter("paySchNo");//支付表号
		String mfrNm = request.getParameter("mfrNm");//厂商名称
		String splNm = request.getParameter("splNm");//供应商名称
		String prdMdl = request.getParameter("prdMdl");//产品型号
		String vinNo = request.getParameter("vin");//车架号
		String licDt = request.getParameter("licDt");//上牌时间
		String provAbbrCd = request.getParameter("provAbbrCd"); 
		String character = request.getParameter("character");
		String vehNoNum = request.getParameter("vehNoNum");
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		PrjPrdLicInfoQueryCondition qc = new PrjPrdLicInfoQueryCondition();
		if (StringUtils.isNotEmpty(cstNm)) {
			qc.setCstNm(cstNm);
		}
		if (StringUtils.isNotEmpty(paySchNo)) {
			qc.setPaySchNo(paySchNo);
		}
		if (StringUtils.isNotEmpty(mfrNm)) {
			qc.setMfrNm(mfrNm);
		}
		if (StringUtils.isNotEmpty(splNm)) {
			qc.setSplNm(splNm);
		}
		if (StringUtils.isNotEmpty(prdMdl)) {
			qc.setPrdMdl(prdMdl);
		}
		if (StringUtils.isNotEmpty(vinNo)) {
			qc.setVinNo(vinNo);
		}
		if (StringUtils.isNotEmpty(licDt)) {
			qc.setLicDt(DateUtils.formatStringToDate(licDt, DateUtils.YYYY_MM_DD));
		}
		if(StringUtils.isNotBlank(provAbbrCd)||StringUtils.isNotBlank(character)||StringUtils.isNotBlank(vehNoNum)){
			String vehNo = "";
			if(StringUtils.isNotBlank(provAbbrCd)){
				vehNo+=provAbbrCd;
			}
			if(StringUtils.isNotBlank(character)){
				vehNo+=character;
			}
			if(StringUtils.isNotBlank(vehNoNum)){
				vehNo+=vehNoNum;
			}
			qc.setVehNo(vehNo);
		}
		qc.setUsrId(CurrentThreadContext.getCurrentUserId());
		page.setCondition(qc);
		Long start = System.currentTimeMillis();
		BaseLogUtils.info(logger,"initList","调用贷前服务-上牌信息分页查询开始");
		ResponseData<ProprdLicensePageResponseDTO> responseData = iProprdLicenseService.searchListPageByCondition(page.getCurrentPage(),page.getEveryPage(),qc,CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		BaseLogUtils.info(logger,"initList","调用贷前服务-上牌信息分页查询结束，用时：" + (System.currentTimeMillis() - start));
		List<PrjPrdLicInfoVO> list = new ArrayList<>();
		if (PreloanResultCodeEnum.SUCCESS.getCode().equals(responseData.getCode())){
			List<PrjPrdLicInfoDTO> dtos = responseData.getData().getLicOrgDTOS();
			for(PrjPrdLicInfoDTO dto:dtos){
				PrjPrdLicInfoVO vo = new PrjPrdLicInfoVO();
				BeanUtils.copyProperties(dto,vo);
				list.add(vo);
			}
		}
		ListPageVO<PrjPrdLicInfoVO> listPage = new ListPageVO<PrjPrdLicInfoVO>(list, responseData.getData().getTotalCount());
		BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}

	/**
	 * 删除数据
	 */
	@RequestMapping(value = "/removeByIds.do", method = {RequestMethod.POST })
	@ResponseBody
	public DataResultVO removeById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String ids = request.getParameter("ids");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
		if(StringUtils.isEmpty(ids)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			return result;
		}
		List<Long> idList = new ArrayList<Long>();
		JSONArray idsArray = JSONArray.fromObject(ids);
		for (Object object : idsArray) {
			idList.add(Long.valueOf(object.toString()));
		}
		try {
			DeleteProprdLicenseRequest deleteProprdLicenseRequest = new DeleteProprdLicenseRequest();
			deleteProprdLicenseRequest.setIds(idList);
			deleteProprdLicenseRequest.setCurrentSysCd(CurrentThreadContext.getCurrentSysCd());
			BaseLogUtils.info(logger, "removeById", "贷前服务调用-上牌删除开始");
			Long start = System.currentTimeMillis();
			iProprdLicenseService.deleteByIds(deleteProprdLicenseRequest);
			BaseLogUtils.info(logger, "removeById", "贷前服务调用-上牌删除调用结束，用时：" +(System.currentTimeMillis() - start));
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "removeById", "删除数据失败.[ids="+ids+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "removeById", "删除数据失败.[ids="+ids+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}

		return result;
	}

	/**
	 * 得到一条记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.error(logger, "getById", "获取数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		
		try {
			PrjPrdLicInfoVO vo = this.prjPrdLicInfoService.selectById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
				BaseLogUtils.info(logger, "getById", "获取数据,数据不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			}
			result.setData(vo);
			BaseLogUtils.info(logger, "getById", "获取数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		}catch(BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getById", "获取失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch(Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "getById", "获取失败.[id="+id+"]"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}

	/**
	 * 新增
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");//id
		String YZ = request.getParameter("YZ");//修改验证信息(tsn)
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		PrjPrdLicInfoVO entity = null;
		Long licId = null;
		try {
			entity = this.getRequestParams(request);
			BaseLogUtils.newLogger("保存车牌号请求参数request=" + JSON.toJSONString(entity)).info();
			if(StringUtils.isNotBlank(id)){
				//修改
				licId = Long.valueOf(id);
				entity.setId(licId);
				 this.prjPrdLicInfoService.modify(entity);
				 result.setSuccess(BaseConstant.IS_YESNO_YES);
					result.setInfo(SysLogConstant.LOG_CMM_UPDATE_SUCC);
			}else{
				//添加
				entity.setIsDel(BaseConstant.IS_YESNO_NO);
				entity.setAudStsCd(FlowConstant.FLOW_CHECK_STATE_NON);
				entity.setCrtTm(new Date());
				entity.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
				licId = this.prjPrdLicInfoService.add(entity);
				result.setSuccess(BaseConstant.IS_YESNO_YES);
				result.setInfo(SysLogConstant.LOG_CMM_ADD_SUCC);
			}
			//TODO ADD PARAM
			result.setData(licId);
			BaseLogUtils.info(logger, "add", "新增数据.[licId="+licId+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}

		return result;
	}

	private PrjPrdLicInfoVO getRequestParams(HttpServletRequest request) {
		PrjPrdLicInfoVO licInfo = new PrjPrdLicInfoVO();
		String dtlId = request.getParameter("dtlId");
		String licDt = request.getParameter("licDt");
		String orgId = request.getParameter("orgId");
		String licRem = request.getParameter("licRem");
		String fileParams = request.getParameter("fileParams");//文件资料
		String vehNo = request.getParameter("vehNo");
		String carOwner = request.getParameter("carOwner");//户主
		String recNo = request.getParameter("recNo");//登记编号
		String YZ = request.getParameter("YZ");//验证上牌(tsn)
		String prjTypCd = request.getParameter("prjTypCd");// 项目类型
		// 上牌状态（2：已上牌；0：未上牌）
		String audStsCd = request.getParameter("audStsCd");
		//换车-项目ID
		String prjId = request.getParameter("prjId");

		if(StringUtils.isNotBlank(audStsCd)){
			licInfo.setAudStsCd(audStsCd);
		}
		if(StringUtils.isNotBlank(YZ)){//(tsn)
			licInfo.setVerification(YZ);
			licInfo.setAudStsCd(YZ);//审核状态
		}

		if(StringUtils.isBlank(licDt)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"上牌时间不能为空！");
		}
        if (StringUtils.isNotEmpty(dtlId)) {
            licInfo.setId(Long.valueOf(dtlId));
        }
		if(StringUtils.isNotBlank(recNo)){
			licInfo.setRecNo(recNo);
		}
		if(StringUtils.isNotBlank(carOwner)){
			licInfo.setCarOwner(carOwner);
		}
		if(StringUtils.isNotBlank(orgId)){
			licInfo.setLicOrgId(Long.valueOf(orgId));
		}
		licInfo.setLicDt(DateUtils.formatStringToDate(licDt, DateUtils.YYYY_MM_DD));
		licInfo.setLicRem(licRem);
		licInfo.setVehNo(vehNo);
		if(StringUtils.isNotBlank(fileParams)){
			//解析附件上传信息
			JSONArray arry = JSONArray.fromObject(fileParams);
			List<SysUlFilesRecVO> uploadFilesRecVOs = new ArrayList<SysUlFilesRecVO>();
			if(arry.size()>0){
				for(int i=0;i<arry.size();i++){
					net.sf.json.JSONObject jsonObject = arry.getJSONObject(i);
					SysUlFilesRecVO sysUlFilesRecVO = new SysUlFilesRecVO();
					sysUlFilesRecVO.setFileNm(jsonObject.getString("fileNm"));
					sysUlFilesRecVO.setAbsLocPath(PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_ROOT_PATH)+jsonObject.getString("filePath"));
					sysUlFilesRecVO.setFilePath(jsonObject.getString("filePath"));
					sysUlFilesRecVO.setSysCd(CurrentThreadContext.getCurrentSysCd());
					sysUlFilesRecVO.setOrgCd(PrjBscInfoConstant.CODE_PRJ_FILE_DEF_ORG);
					uploadFilesRecVOs.add(sysUlFilesRecVO);
				}
				licInfo.setUploadFilesRecVOs(uploadFilesRecVOs);
			}

		}
		if (StringUtils.isNotEmpty(prjId)) {
			licInfo.setPrjId(Long.valueOf(prjId));
		}
		licInfo.setMdfTm(new Date());
		licInfo.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
		return licInfo;
	}
	/**
	 * 修改
	 */
	@RequestMapping(value = "/modify.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "modify", "修改数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		PrjPrdLicInfoVO entity = null;
		try {
			entity = new PrjPrdLicInfoVO();
			entity.setId(Long.valueOf(id));
			//entity.setName(name);
			//TODO ADD PARAM
			boolean success = this.prjPrdLicInfoService.modify(entity);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
				BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
			}
			BaseLogUtils.info(logger, "modify", "修改成功.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	/**
	 * 初始化项目产品列表
	 */
	@RequestMapping(value = "/initPrjPrdDtlList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initPrjPrdDtlList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String dtlIdStr = request.getParameter("dtlId");//产品明细ID
		
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		Long dtlId = null;
		if(StringUtils.isNotBlank(dtlIdStr)){
			dtlId = Long.valueOf(dtlIdStr);
		}
		List<PrjPrdLicInfoVO> prjprdlicinfoList  = this.prjPrdLicInfoService.searchInitPrjPrdDtlList(Long.valueOf(dtlId));
		if(CollectionUtils.isNotEmpty(prjprdlicinfoList)){
			for (PrjPrdLicInfoVO prjPrdLicInfoVO : prjprdlicinfoList) {
				if(null!=prjPrdLicInfoVO.getGuidePc()){
					prjPrdLicInfoVO.setGuidePc(DecimalUtils.convertFenToYuan(prjPrdLicInfoVO.getGuidePc().longValue()));
				}
			}
		}
		ListPageVO<PrjPrdLicInfoVO> listPage = new ListPageVO<PrjPrdLicInfoVO>(prjprdlicinfoList, prjprdlicinfoList.size());
		BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}
	


	/**
	 *  初始化上传附件信息
	 * @param request
	 * @param response
	 * @return
	 */
    @RequestMapping(value = "/initMateList.do")
    @ResponseBody
    public Object initMateList(HttpServletRequest request) {
       
        //产品明细ID
        String prjPrdDtlId = request.getParameter("prjPrdDtlId");
        String from = request.getParameter("from");//mtg抵押 、上牌
        
        CapPayInfoQueryCondition qc = new CapPayInfoQueryCondition();
       
        if (StringUtils.isNotEmpty(prjPrdDtlId)) {
            qc.setPrjPrdDtlId(Long.valueOf(prjPrdDtlId));
        }
       
        BaseLogUtils.info(logger, null, "上传附件信息:" + JSONObject.toJSONString(qc), CurrentThreadContext.getCurrentUserName());
        List<CapPayMaterialVo> list = this.prjPrdLicInfoService.searchMateList(qc,from);
        if (CollectionUtils.isNotEmpty(list)) {
            return new ListPageVO<CapPayMaterialVo>(list, list.size());
        }
        return null;
    }

}

